import java.util.*;

public class _04_LongestIncreasingSequence {
	
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		String input = in.nextLine();
		in.close();
		
		String[] inputNumbersAsStrings = input.split(" ");
		int[] inputNumbers = new int[inputNumbersAsStrings.length];
		
		for (int i = 0; i < inputNumbers.length; i++) {
			
			inputNumbers[i] = Integer.parseInt(inputNumbersAsStrings[i]);
		}
		
		List<Integer> sequence = new ArrayList<Integer>();
		List<ArrayList<Integer>> sequences = new ArrayList<ArrayList<Integer>>();
		
		for (int i = 0; i < inputNumbers.length - 1; i++) {
			
			if (inputNumbers[i] > inputNumbers[i + 1]) {
				
				sequence.add(inputNumbers[i]);
				sequences.add(new ArrayList<Integer>(sequence));
				sequence.clear();
			}
			else {
				
				sequence.add(inputNumbers[i]);
			}
		}
		
		if (inputNumbers[inputNumbers.length - 1] > inputNumbers[inputNumbers.length - 2]) {
			
			sequence.add(inputNumbers[inputNumbers.length - 1]);
			sequences.add(new ArrayList<Integer>(sequence));
		}
		else {
			
			sequence.clear();
			sequence.add(inputNumbers[inputNumbers.length - 1]);
			sequences.add(new ArrayList<Integer>(sequence));
		}
		
		int sizeOfLongest = sequences.get(0).size();
		int indexOfLongest = 0;
		
		for (int i = 0; i < sequences.size(); i++) {
			
			if (sequences.get(i).size() > sizeOfLongest) {
				
				sizeOfLongest = sequences.get(i).size();
				indexOfLongest = i;
			}
			
			for (int j = 0; j < sequences.get(i).size(); j++) {
				
				System.out.print(sequences.get(i).get(j) + " ");
			}
			
			System.out.println();
		}
		
		System.out.print("Longest: ");
		
		for (int j = 0; j < sequences.get(indexOfLongest).size(); j++) {
			
			System.out.print(sequences.get(indexOfLongest).get(j) + " ");
		}
	}
}